#ifndef _BASIC_H_
#define _BASIC_H_

uint8_t color[12][4]{

};

void adjust0(int time) // Apply to the function that not light all LEDs
{
  FastLED.setBrightness(Brightness);
  FastLED.show();
  delay(time);
  FastLED.clear();
}

uint8_t Position(short x, short y)
{
  uint8_t n;
  if ((x < 13) && (y < 5) && (x >= 0) && (y >= 0))
  {
    n = x + 13 * y;
  }
  else
    n = 100;
  return n;
}

void myshow(short x, short y)
{
  if ((x < 13) && (y < 5) && (x >= 0) && (y >= 0))
  {
    leds[Position(x, y)] = CHSV(color[x][y], 100, 255);
  }
}

uint8_t mult2(uint8_t mul)
{
  uint8_t i, tem;
  if (mul == 0)
    tem = 1;

  else
  {
    tem = 1;
    for (i = 0; i < mul; i++)
    {
      tem = 2 * tem;
    }
  }
  return tem;
}

void show16(int num16, int y, uint8_t bit, short pos)
{
  uint8_t count, x;
  uint8_t num = num16;
  // n>=0
  for (count = 0; count < bit; count++)
  {
    if (num / mult2((bit - count) - 1) == 1)
    {
      x = (bit - count) - 1 + pos;
      myshow(x, y);
      num = num - mult2((bit - count) - 1);
    }
  }
}

void printarr(uint8_t *ch, uint8_t size, uint8_t bit, short pos)
{
  uint8_t count;
  for (count = 0; count < size; count++)
  {
    show16(ch[count], count, bit, pos);
  }
}

uint8_t printsinglechar(char ch, short pos)
{
  uint8_t ch0[] = {0x7, 0x5, 0x5, 0x5, 0x7};
  uint8_t ch1[] = {0x2, 0x3, 0x2, 0x2, 0x7};
  uint8_t ch2[] = {0x7, 0x4, 0x7, 0x1, 0x7};
  uint8_t ch3[] = {0x7, 0x4, 0x7, 0x4, 0x7};
  uint8_t ch4[] = {0x5, 0x5, 0x7, 0x4, 0x4};
  uint8_t ch5[] = {0x7, 0x1, 0x7, 0x4, 0x7};
  uint8_t ch6[] = {0x7, 0x1, 0x7, 0x5, 0x7};
  uint8_t ch7[] = {0x7, 0x5, 0x4, 0x4, 0x4};
  uint8_t ch8[] = {0x7, 0x5, 0x7, 0x5, 0x7};
  uint8_t ch9[] = {0x7, 0x5, 0x7, 0x4, 0x7};

  uint8_t chA[] = {0x2, 0x5, 0x7, 0x5, 0x5}; /*"未命名文件",0*/
  uint8_t chB[] = {0x3, 0x5, 0x7, 0x5, 0x3}; /*"未命名文件",0*/
  uint8_t chC[] = {0x7, 0x1, 0x1, 0x1, 0x7}; /*"未命名文件",0*/

  uint8_t chD[] = {0x7, 0x9, 0x9, 0x9, 0x7}; /*"未命名文件",0*/
  uint8_t chE[] ={0x15, 0x1, 0x15, 0x1, 0x15}; /*"未命名文件",0*/
  uint8_t chF[] ={0x15, 0x1, 0x15, 0x1, 0x1}; /*"未命名文件",0*/
  uint8_t chG[] = {0x15, 0x1, 0x13, 0x9, 0x15}; /*"未命名文件",0*/
  uint8_t chH[] = {0x9, 0x9, 0x15, 0x9, 0x9};   /*"未命名文件",0*/
  uint8_t chI[] = {0x7, 0x2, 0x2, 0x2, 0x7};    /*"未命名文件",0*/
  uint8_t chJ[] = {0x8, 0x8, 0x8, 0x4, 0x3};      /*"未命名文件",0*/
  uint8_t chK[] = {0x9, 0x5, 0x3, 0x5, 0x9};      /*"未命名文件",0*/
  uint8_t chL[] = {0x1, 0x1, 0x1, 0x1, 0x15};     /*"未命名文件",0*/
  uint8_t chM[] = {0x17, 0x27, 0x21, 0x21, 0x17}; /*"未命名文件",5*/
  uint8_t chN[] = {0x17, 0x19, 0x21, 0x25, 0x17}; /*"未命名文件",5*/
  uint8_t chO[] = {0x15, 0x9, 0x9, 0x9, 0x15}; /*"未命名文件",0*/
  uint8_t chP[] = {0x15, 0x9, 0x15, 0x1, 0x1}; /*"未命名文件",0*/
  uint8_t chQ[] ={0x15, 0x9, 0x9, 0x13, 0x19}; /*"未命名文件",5*/

  switch (ch)
  {
  case 0:
    printarr(ch0, sizeof(ch0), 4, pos);
    break;
  case 1:
    printarr(ch1, sizeof(ch1), 4, pos);
    break;
  case 2:
    printarr(ch2, sizeof(ch2), 4, pos);
    break;
  case 3:
    printarr(ch3, sizeof(ch3), 4, pos);
    break;
  case 4:
    printarr(ch4, sizeof(ch4), 4, pos);
    break;
  case 5:
    printarr(ch5, sizeof(ch5), 4, pos);
    break;
  case 6:
    printarr(ch6, sizeof(ch6), 4, pos);
    break;
  case 7:
    printarr(ch7, sizeof(ch7), 4, pos);
    break;
  case 8:
    printarr(ch8, sizeof(ch8), 4, pos);
    break;
  case 9:
    printarr(ch9, sizeof(ch9), 4, pos);
    break;

  case '0':
    printarr(ch0, sizeof(ch0), 4, pos);
    break;
  case '1':
    printarr(ch1, sizeof(ch1), 4, pos);
    break;
  case '2':
    printarr(ch2, sizeof(ch2), 4, pos);
    break;
  case '3':
    printarr(ch3, sizeof(ch3), 4, pos);
    break;
  case '4':
    printarr(ch4, sizeof(ch4), 4, pos);
    break;
  case '5':
    printarr(ch5, sizeof(ch5), 4, pos);
    break;
  case '6':
    printarr(ch6, sizeof(ch6), 4, pos);
    break;
  case '7':
    printarr(ch7, sizeof(ch7), 4, pos);
    break;
  case '8':
    printarr(ch8, sizeof(ch8), 4, pos);
    break;
  case '9':
    printarr(ch9, sizeof(ch9), 4, pos);
    break;

  case 'A':
    printarr(chA, sizeof(chA), 4, pos);
    return 4;
    break;
  case 'B':
    printarr(chB, sizeof(chB), 4, pos);
    return 4;
    break;
  case 'C':
    printarr(chC, sizeof(chC), 4, pos);
    return 4;
    break;
  case 'D':
    printarr(chD, sizeof(chD), 4, pos);
    return 4;
    break;
  case 'E':
    printarr(chE, sizeof(chE), 5, pos);
    return 4;
    break;
  case 'F':
    printarr(chF, sizeof(chF), 5, pos);
    return 4;
    break;
  case 'G':
    printarr(chG, sizeof(chG), 4, pos);
    return 4;
    break;
  case 'H':
    printarr(chH, sizeof(chH), 4, pos);
    return 4;
    break;
  case 'I':
    printarr(chI, sizeof(chI), 4, pos);
    return 4;
    break;
  case 'J':
    printarr(chJ, sizeof(chJ), 4, pos);
    return 4;
    break;
  case 'K':
    printarr(chK, sizeof(chK), 4, pos);
    return 4;
    break;
  case 'L':
    printarr(chL, sizeof(chL), 4, pos);
    return 4;
    break;
  case 'M':
    printarr(chM, sizeof(chM), 5, pos);
    return 4;
    break;
  case 'N':
    printarr(chN, sizeof(chN), 5, pos);
    return 4;
    break;
  case 'O':
    printarr(chO, sizeof(chO), 4, pos);
    return 4 ;
    break;
  case 'P':
    printarr(chP, sizeof(chP), 4, pos);
    return 4;
    break;
  case 'Q':
    printarr(chQ, sizeof(chQ), 5, pos);
    return 4;
    break;

  default:
    return 255;
    break;
  }
  return 5;
}

void print2num(uint8_t num, short pos)
{
  printsinglechar(num / 10, pos);
  printsinglechar(num % 10, pos + 3);
}

void printtime(uint8_t t1, uint8_t t2)
{
  print2num(t1, 0);
  myshow(6, 1);
  myshow(6, 3);
  print2num(t2, 7);
}

void statistic_print(String sentence, short pos)
{
  uint8_t i;

  for (i = 0; i < sentence.length(); i++)
  {
    pos = printsinglechar(sentence[i], pos) + pos;
  }
}

void print(String sen)
{
  short pos;
  uint8_t i;
  for (i = 0, pos = 0; i < 4 * sen.length(); i++)
  {
    statistic_print(sen, pos - i);
    adjust0(1000);
  }
}

#endif
